jsx3.require("tibco.admin.enterpriseAssets.EnterpriseAssetsTabInterface");

/**
 * General Details
 */
jsx3.lang.Package.definePackage("tibco.admin.environments.genDtls", function (machines) {
});

/**
 * General Details
 */
jsx3.lang.Class.defineClass("tibco.admin.environments.genDtls.GenDtls",
        jsx3.lang.Object,
        [tibco.admin.environments.EnvironmentsInterface],
        function (plugin) {
            plugin.instance = null

            plugin.prototype.init = function() {
                this.jsxsuper();
                tibco.admin.Main.loadResource("tibco/admin/environments/genDtls/jss/jss.xml", "tibco.admin", "jss31", "ljss", false);
            }

            plugin.prototype.getNamespace = function() {
                return "tibco.admin";
            }

            plugin.prototype.destroyPlugin = function() {
            }

            plugin.getInstance = function(args) {
                if(!this.instance) {
                    this.instance = new tibco.admin.environments.genDtls.GenDtls();
                }
                return this.instance;
            }

            plugin.prototype.loadComponent = function(parent) {
                if(!this.loading) {
                    this.loading = true;
                    var me = this;
                    tibco.admin.Main.loadUIResourceAsync(parent, "tibco.admin", "tibco/admin/environments/genDtls/components/general.xml", me, me.onUILoaded);
                }
            }

            plugin.prototype.getButtonText = function(parent) {
                return tibco.admin.Main.getServer().getDynamicProperty("@@lblSectionTitle_31");
            }

            plugin.prototype.setEnvId = function(id) {
                this.envId = id;
            }

            plugin.prototype.setNodeIds = function(arrIds) {
                if(this.isInEditMode() && !this.isAddMode) {
                    if((arrIds && (arrIds.length == 1) && (arrIds[0] != this.nodeId)) || (this.nodeId && (!arrIds || (arrIds.length != 1)))) {
                        tibco.admin.Main.alert(tibco.admin.Main.getServer().getDynamicProperty("@@msgCannotUpdateNodeIdTitle_31"), tibco.admin.Main.getServer().getDynamicProperty("@@msgCannotUpdateNodeIdMessage_31"));
                    }
                    return;
                }
                if(arrIds && (arrIds.length == 1)) {
                    this.nodeId = arrIds[0];
                    this.dontLoadProducts = false;
                }
                else {
                    this.nodeId = null;
                }
                if(!this.isAddMode && this.block && this.nodeId) {
                    this.loadDetails();
                }
                else if(this.block) {
                    this.clearFields();
                }
            }

            plugin.prototype.setNodeName = function(nodeName) {
                this.nodeName = nodeName;
            }

            plugin.prototype.setNodeState = function(nodeState) {
                this.nodeState = nodeState;
                if(this.block) {
                    this.block.getDescendantOfName("btnEdit_31").setEnabled((nodeState == "Starting") ? jsx3.gui.Form.STATEDISABLED : jsx3.gui.Form.STATEENABLED, true);
                }
            }

            plugin.prototype.onAfterComponentUnloaded = function() {
                if(this.isInEditMode()) {
                    this.endEditMode();
                }
                this.envId = null;
                this.isAddMode = false;
                this.nodeId = null;
                this.block = null;
                if(this.loading) {
                    delete this.loading;
                }
            }

            plugin.prototype.loadProducts = function() {
                if(this.dontLoadProducts) {
                    return;
                }
                try {
                    var objService = tibco.admin.Main.loadService("tibco.admin", "tibco/admin/environments/genDtls/rules/getProductsInEnvironment.xml", "getProductsInEnvironment");
                    if(tibco.admin.Main.getServer().getEnv("MODE")) {
                        objService.setEndpointURL(tibco.admin.util.ServiceHelper.getInventoryEndpointURL());
                    }

                    //subscribe and call
                    var me = this;
                    objService.envId = this.envId;
                    objService.subscribe(jsx3.net.Service.ON_SUCCESS, me, me.onloadProductsSuccess);
                    objService.subscribe(jsx3.net.Service.ON_ERROR, me, me.onloadProductsError);
                    objService.subscribe(jsx3.net.Service.ON_INVALID, me, me.onloadProductsInvalid);
                    objService.doCall();
                }
                catch(ex) {
                    tibco.admin.Main.logException(ex, "Error in tibco.admin.environments.genDtls.GenDtls.loadProducts");
                }
            }

            plugin.prototype.onloadProductsSuccess = function(objEvent) {
                if(objEvent.target.hadError()) {
                    this.dontLoadProducts = true;
                    if(this.isInEditMode()) {
                        this.doCancelEdits();
                    }
                    return;
                }
                // parse out machines/products
                var cache = tibco.admin.Main.getServer().getCache();
                var doc = cache.getDocument("getProductsInEnvironment_31");
                var newDoc = jsx3.xml.CDF.Document.newDocument();
                var iter = doc.getChildNodes().iterator();
                while(iter.hasNext()) {
                    var node = iter.next();
                    var newNode = newDoc.createNode(jsx3.xml.Entity.TYPEELEMENT, "record");
                    newNode.setAttribute("jsxid", node.getAttribute("jsxid"));
                    newNode.setAttribute("jsxtext", node.getAttribute("hostName"));
                    newNode.setAttribute("canRunAsNTService", node.getAttribute("canRunAsNTService"));
                    newDoc.appendChild(newNode);
                }
                cache.setDocument("selectMachine_31", newDoc);
                if(!this.isInEditMode() && this.nodeId) {
                    this.loadDetails();
                }
                else {
                    this.loadServiceBusConfigurations();
                }
            }

            plugin.prototype.onloadProductsError = function(objEvent) {
                if(objEvent.target.hadError()) {
                    this.dontLoadProducts = true;
                    if(this.isInEditMode()) {
                        this.doCancelEdits();
                    }
                    return;
                }
                if(!this.isInEditMode() && this.nodeId) {
                    this.loadDetails();
                }
                else {
                    this.loadServiceBusConfigurations();
                }
            }

            plugin.prototype.onloadProductsInvalid = function(objEvent) {
                if(objEvent.target.hadError()) {
                    this.dontLoadProducts = true;
                    if(this.isInEditMode()) {
                        this.doCancelEdits();
                    }
                    return;
                }
                if(!this.isInEditMode() && this.nodeId) {
                    this.loadDetails();
                }
                else {
                    this.loadServiceBusConfigurations();
                }
            }

            plugin.prototype.loadServiceBusConfigurations = function() {
                if(this.dontLoadProducts) {
                    return;
                }
                try {
                    var objService = tibco.admin.Main.loadService("tibco.admin", "tibco/admin/environments/genDtls/rules/getServiceBusConfigurations.xml", "getServiceBusConfigurations");
                    if(tibco.admin.Main.getServer().getEnv("MODE")) {
                        objService.setEndpointURL(tibco.admin.util.ServiceHelper.getEnvironmentEndpointURL());
                    }

                    //subscribe and call
                    var me = this;
                    objService.envId = this.envId;
                    objService.subscribe(jsx3.net.Service.ON_SUCCESS, me, me.onloadServiceBusConfigurationsSuccess);
                    objService.subscribe(jsx3.net.Service.ON_ERROR, me, me.onloadServiceBusConfigurationsError);
                    objService.subscribe(jsx3.net.Service.ON_INVALID, me, me.onloadServiceBusConfigurationsInvalid);
                    objService.doCall();
                }
                catch(ex) {
                    tibco.admin.Main.logException(ex, "Error in tibco.admin.environments.genDtls.GenDtls.loadServiceBusConfigurations");
                }
            }

            plugin.prototype.onloadServiceBusConfigurationsSuccess = function(objEvent) {
                if(!this.isAddMode && this.nodeId) {
                    this.loadDetails();
                }
                else {
                    this.clearFields();
                }
            }

            plugin.prototype.onloadServiceBusConfigurationsError = function(objEvent) {
                if(!this.isAddMode && this.nodeId) {
                    this.loadDetails();
                }
                else {
                    this.clearFields();
                }
            }

            plugin.prototype.onloadServiceBusConfigurationsInvalid = function(objEvent) {
                if(!this.isAddMode && this.nodeId) {
                    this.loadDetails();
                }
                else {
                    this.clearFields();
                }
            }

            plugin.prototype.loadDetails = function() {
                try {
                    var objService = tibco.admin.Main.loadService("tibco.admin", "tibco/admin/environments/genDtls/rules/getNodeDetails.xml", "getNodeDetails");
                    if(tibco.admin.Main.getServer().getEnv("MODE")) {
                        objService.setEndpointURL(tibco.admin.util.ServiceHelper.getNodeEndpointURL());
                    }

                    //subscribe and call
                    var me = this;
                    objService.handler = me;
                    objService.subscribe(jsx3.net.Service.ON_SUCCESS, me, me.onloadDetailsSuccess);
                    objService.subscribe(jsx3.net.Service.ON_ERROR, me, me.onloadDetailsError);
                    objService.subscribe(jsx3.net.Service.ON_INVALID, me, me.onloadDetailsInvalid);
                    objService.doCall();
                }
                catch(ex) {
                    tibco.admin.Main.logException(ex, "Error in tibco.admin.environments.genDtls.GenDtls.loadDetails");
                }
            }

            plugin.prototype.onMachineSelected = function(id) {
                var doc = tibco.admin.Main.getServer().getCache().getDocument("getProductsInEnvironment_31");
                var machNode = doc.getRecordNode(id);
                var canRunAsNTService = machNode && (machNode.getAttribute("canRunAsNTService") == "true");
                if(canRunAsNTService) {
                    this.block.getDescendantOfName("blkEditInstallAsNTService_31").getChild(0).setEnabled(jsx3.gui.Form.STATEENABLED, true);
                    this.block.getDescendantOfName("blkEditInstallAsNTService_31").getChild(1).setEnabled(jsx3.gui.Form.STATEENABLED, true);
                }
                else {
                    this.block.getDescendantOfName("blkEditInstallAsNTService_31").getChild(0).setEnabled(jsx3.gui.Form.STATEDISABLED, true);
                    this.block.getDescendantOfName("blkEditInstallAsNTService_31").getChild(1).setEnabled(jsx3.gui.Form.STATEDISABLED, true);
                }
                this.block.getDescendantOfName("blkEditInstallAsNTService_31").getChild(1).setSelected(jsx3.gui.RadioButton.SELECTED);
                this.updateProductList(machNode);
                return canRunAsNTService;
            }

            plugin.prototype.updateProductList = function(machine) {
                var machNode = machine;
                if(!machNode) {
                    tibco.admin.Main.getServer().getCache().clearById("selectProduct_31");
                }
                else if(!(machNode instanceof jsx3.xml.Entity)) {
                    var iter = tibco.admin.Main.getServer().getCache().getDocument("getProductsInEnvironment_31").getChildNodes();
                    while(iter.hasNext()) {
                        var node = iter.next();
                        if(node.getAttribute("hostName") == machNode) {
                            machNode = node;
                            break;
                        }
                    }
                }
                var prodIter = machNode.getChildNodes();
                var newDoc = jsx3.xml.CDF.Document.newDocument();
                while(prodIter.hasNext()) {
                    var prod = prodIter.next();
                    var newNode = newDoc.createNode(jsx3.xml.Entity.TYPEELEMENT, "record");
                    newNode.setAttribute("tibcoHome", prod.getAttribute("tibcoHome"));
                    newNode.setAttribute("installDir", prod.getAttribute("installDir"));
                    newNode.setAttribute("major", prod.getAttribute("major"));
                    newNode.setAttribute("minor", prod.getAttribute("minor"));
                    newNode.setAttribute("maintenance", prod.getAttribute("maintenance"));
                    var prodString = prod.getAttribute("installDir") + " " + prod.getAttribute("major") + "." + prod.getAttribute("minor") + "." + prod.getAttribute("maintenance");
                    var fragment = prod.getAttribute("fragment");
                    if(fragment) {
                        newNode.setAttribute("fragment", prod.getAttribute("fragment"));
                        prodString += " " + fragment;
                    }
                    newNode.setAttribute("jsxid", prodString);
                    newNode.setAttribute("jsxtext", prodString);
                    newDoc.appendChild(newNode);
                }
                newDoc.setSelectionLanguage("XPath");
                tibco.admin.Main.getServer().getCache().setDocument("selectProduct_31", newDoc);
                this.block.getDescendantOfName("slctEditProduct_31").setValue(null);
            }

            plugin.prototype.getIdForText = function(doc, text) {
                var iter = doc.getChildNodes().iterator();
                while(iter.hasNext()) {
                    var node = iter.next();
                    if(node.getAttribute("jsxtext") == text) {
                        return node.getAttribute("jsxid");
                    }
                }
                return null;
            }

            plugin.prototype.getRecordForId = function(doc, id) {
                var iter = doc.getChildNodes().iterator();
                while(iter.hasNext()) {
                    var node = iter.next();
                    if(node.getAttribute("jsxid") == id) {
                        return node;
                    }
                }
                return null;
            }

            plugin.prototype.onloadDetailsSuccess = function(objEvent) {
                var doc = tibco.admin.Main.getServer().getCache().getDocument("getNodeDetails_31");
                if(doc) {

                    var val = doc.getAttribute("nodeName");
                    this.block.getDescendantOfName("lblViewNodeName_31").setText(val, true);
                    this.block.getDescendantOfName("txtboxEditNodeName_31").setValue(val);

                    val = doc.getAttribute("description");
                    this.block.getDescendantOfName("lblViewDescription_31").setText(val, true);
                    this.block.getDescendantOfName("blkEditDescription_31").getChild(0).setValue(val);

                    val = doc.getAttribute("hostName");
                    this.block.getDescendantOfName("lblViewMachineName_31").setText(val, true);
                    var id = this.getIdForText(this.block.getDescendantOfName("slctEditMachineName_31").getXML(), val);
                    this.block.getDescendantOfName("slctEditMachineName_31").setValue(id);

                    val = doc.getAttribute("runAsNTService");
                    this.block.getDescendantOfName("lblViewInstallAsNTService_31").
                            setText(tibco.admin.Main.getServer().getDynamicProperty("@addin@radBtn " + (val == "true" ? "Yes" : "No")), true);
                    if(this.isInEditMode()) {
                        var canRunAsNTService = this.onMachineSelected(id);
                        if (canRunAsNTService)
                        {
                            this.block.getDescendantOfName("blkEditInstallAsNTService_31").
                                    getChild((val == "true") ? 0 : 1).setSelected(jsx3.gui.RadioButton.SELECTED);
                        }
                    }

                    val = doc.getAttribute("installDir") + " " + doc.getAttribute("major") + "." + doc.getAttribute("minor") + "." + doc.getAttribute("maintenance");
                    var fragment = doc.getAttribute("fragment");
                    if(fragment) {
                        val += " " + fragment;
                    }
                    this.block.getDescendantOfName("lblViewProduct_31").setText(val, true);
                    this.block.getDescendantOfName("slctEditProduct_31").setValue(this.getIdForText(this.block.getDescendantOfName("slctEditProduct_31").getXML(), val));

                    val = doc.getAttribute("transportConfigName");
                    this.block.getDescendantOfName("lblViewMessageServer_31").setText(val, true);
                    this.block.getDescendantOfName("slctEditMessageServer_31").setValue(this.getIdForText(this.block.getDescendantOfName("slctEditMessageServer_31").getXML(), val));

                    val = doc.getAttribute("namingPort");
                    this.block.getDescendantOfName("lblViewNamingPort_31").setText(val, true);
                    this.block.getDescendantOfName("txtboxEditNamingPort_31").setValue(val);

                    val = doc.getAttribute("httpPort");
                    this.block.getDescendantOfName("lblViewHTTPPort_31").setText(val, true);
                    this.block.getDescendantOfName("txtboxEditHTTPPort_31").setValue(val);

                    if(this.isInEditMode()) {
                        val = (doc.getAttribute("state").toLowerCase().indexOf("installed") != -1 || doc.getAttribute("state").toLowerCase().indexOf("running") != -1);
                        this.block.getDescendantOfName("txtboxEditNodeName_31").setEnabled(val ? jsx3.gui.Form.STATEDISABLED : jsx3.gui.Form.STATEENABLED, true);
                        this.block.getDescendantOfName("slctEditMachineName_31").setEnabled(val ? jsx3.gui.Form.STATEDISABLED : jsx3.gui.Form.STATEENABLED, true);
                        this.block.getDescendantOfName("txtboxEditNamingPort_31").setEnabled(val ? jsx3.gui.Form.STATEDISABLED : jsx3.gui.Form.STATEENABLED, true);
                        this.block.getDescendantOfName("txtboxEditHTTPPort_31").setEnabled(val ? jsx3.gui.Form.STATEDISABLED : jsx3.gui.Form.STATEENABLED, true);
                        this.block.getDescendantOfName("slctEditProduct_31").setEnabled(val ? jsx3.gui.Form.STATEDISABLED : jsx3.gui.Form.STATEENABLED, true);
                        if (canRunAsNTService)
                        {
                            this.block.getDescendantOfName("blkEditInstallAsNTService_31").getChild(0).setEnabled(val ? jsx3.gui.Form.STATEDISABLED : jsx3.gui.Form.STATEENABLED, true);
                            this.block.getDescendantOfName("blkEditInstallAsNTService_31").getChild(1).setEnabled(val ? jsx3.gui.Form.STATEDISABLED : jsx3.gui.Form.STATEENABLED, true);
                        }
                        this.block.getDescendantOfName("txtboxEditNodeName_31").setEnabled(jsx3.gui.Form.STATEDISABLED, true);
                    }
                    this.initializeParam();
                }
            }

            plugin.prototype.onloadDetailsError = function(objEvent) {
            }

            plugin.prototype.onloadDetailsInvalid = function(objEvent) {
            }

            plugin.prototype.newNode = function() {
                this.isAddMode = true;
                this.dontLoadProducts = false;
                this.doEditMode();
                this.initializeParam();
            }

            plugin.prototype.doEditMode = function() {
                if(!this.nodeId && !this.isAddMode) return;
                //TODO: clear cache doc

                this.beginEditMode();
                this.block.getDescendantOfName("lblViewNodeName_31").setDisplay(jsx3.gui.Block.DISPLAYNONE, true).setText("", true);
                this.block.getDescendantOfName("lblViewDescription_31").setDisplay(jsx3.gui.Block.DISPLAYNONE, true).setText("", true);
                this.block.getDescendantOfName("lblViewMachineName_31").setDisplay(jsx3.gui.Block.DISPLAYNONE, true).setText("", true);
                this.block.getDescendantOfName("lblViewInstallAsNTService_31").setDisplay(jsx3.gui.Block.DISPLAYNONE, true).setText("", true);

                this.block.getDescendantOfName("lblViewProduct_31").setDisplay(jsx3.gui.Block.DISPLAYNONE, true).setText("", true);

                this.block.getDescendantOfName("lblViewMessageServer_31").setDisplay(jsx3.gui.Block.DISPLAYNONE, true).setText("", true);
                this.block.getDescendantOfName("lblViewNamingPort_31").setDisplay(jsx3.gui.Block.DISPLAYNONE, true).setText("", true);
                this.block.getDescendantOfName("lblViewHTTPPort_31").setDisplay(jsx3.gui.Block.DISPLAYNONE, true).setText("", true);

                this.block.getDescendantOfName("txtboxEditNodeName_31").setDisplay(jsx3.gui.Block.DISPLAYBLOCK, true).setValue("", true);
                this.block.getDescendantOfName("blkEditDescription_31").getChild(0).setValue(null, true);
                this.block.getDescendantOfName("blkEditDescription_31").setDisplay(jsx3.gui.Block.DISPLAYBLOCK, true);
                this.block.getDescendantOfName("slctEditMachineName_31").setDisplay(jsx3.gui.Block.DISPLAYBLOCK, true).setValue(null, true);
                this.block.getDescendantOfName("blkEditInstallAsNTService_31").setDisplay(jsx3.gui.Block.DISPLAYBLOCK, true).getChild(1).setSelected(jsx3.gui.RadioButton.SELECTED);
                this.block.getDescendantOfName("slctEditProduct_31").setDisplay(jsx3.gui.Block.DISPLAYBLOCK, true).setValue(null, true);
                this.block.getDescendantOfName("slctEditMessageServer_31").setDisplay(jsx3.gui.Block.DISPLAYBLOCK, true).setValue(null, true);
                this.block.getDescendantOfName("txtboxEditNamingPort_31").setDisplay(jsx3.gui.Block.DISPLAYBLOCK, true).setValue("", true);
                this.block.getDescendantOfName("txtboxEditHTTPPort_31").setDisplay(jsx3.gui.Block.DISPLAYBLOCK, true).setValue("", true);

                this.block.getDescendantOfName("btnEdit_31").setDisplay(jsx3.gui.Block.DISPLAYNONE, true);
                this.block.getDescendantOfName("btnCancel_31").setDisplay(jsx3.gui.Block.DISPLAYBLOCK, true);
                this.block.getDescendantOfName("btnSave_31").setDisplay(jsx3.gui.Block.DISPLAYBLOCK, true);

                this.block.getDescendantOfName("txtboxEditNodeName_31").setEnabled(jsx3.gui.Form.STATEENABLED, true);
                this.block.getDescendantOfName("slctEditMachineName_31").setEnabled(jsx3.gui.Form.STATEENABLED, true);
                this.block.getDescendantOfName("slctEditProduct_31").setEnabled(jsx3.gui.Form.STATEENABLED, true);
                this.block.getDescendantOfName("txtboxEditNamingPort_31").setEnabled(jsx3.gui.Form.STATEENABLED, true);

                this.block.getDescendantOfName("blkEditInstallAsNTService_31").getChild(0).setEnabled(jsx3.gui.Form.STATEENABLED, true);
                this.block.getDescendantOfName("blkEditInstallAsNTService_31").getChild(1).setEnabled(jsx3.gui.Form.STATEENABLED, true);

                this.loadProducts();

            }

            plugin.prototype.clearFields = function() {
                try {
                    this.block.getDescendantOfName("lblViewNodeName_31").setText("", true);
                    this.block.getDescendantOfName("lblViewDescription_31").setText("", true);
                    this.block.getDescendantOfName("lblViewMachineName_31").setText("", true);
                    this.block.getDescendantOfName("lblViewInstallAsNTService_31").setText("", true);
                    this.block.getDescendantOfName("lblViewProduct_31").setText("", true);
                    this.block.getDescendantOfName("lblViewMessageServer_31").setText("", true);
                    this.block.getDescendantOfName("lblViewNamingPort_31").setText("", true);
                    this.block.getDescendantOfName("lblViewHTTPPort_31").setText("", true);

                    this.block.getDescendantOfName("txtboxEditNodeName_31").setValue("", true);
                    this.block.getDescendantOfName("blkEditDescription_31").getChild(0).setValue(null, true);
                    this.block.getDescendantOfName("slctEditMachineName_31").setValue(null, true);
                    this.block.getDescendantOfName("blkEditInstallAsNTService_31").getChild(1).setSelected(jsx3.gui.RadioButton.SELECTED);
                    this.block.getDescendantOfName("slctEditProduct_31").setValue(null, true);
                    this.block.getDescendantOfName("slctEditMessageServer_31").setValue(null, true);
                    this.block.getDescendantOfName("txtboxEditNamingPort_31").setValue("", true);
                    this.block.getDescendantOfName("txtboxEditHTTPPort_31").setValue("", true);
                }
                catch(ex) {
                    // do nothing...this just means they aren't loaded yet!
                }
            }

            plugin.prototype.doCancelEdits = function() {
                this.isAddMode = false;
                this.doViewMode();
                this.addCompleted(null);
            }

            plugin.prototype.getConfirmText = function() {
                return tibco.admin.Main.getServer().getDynamicProperty("@@Confirm Discard Text_31");
            }

            plugin.prototype.saveClicked = function() {
                if(this.isAddMode) {
                    this.doAddNode();
                }
                else {
                    this.doEditNode();
                }
            }

            plugin.prototype.doAddNode = function() {
                try {
                    var objService = tibco.admin.Main.loadService("tibco.admin", "tibco/admin/environments/genDtls/rules/addNode.xml", "addNode");
                    if(tibco.admin.Main.getServer().getEnv("MODE")) {
                        objService.setEndpointURL(tibco.admin.util.ServiceHelper.getNodeEndpointURL());
                    }

                    //subscribe and call
                    objService.nodeName = this.block.getDescendantOfName("txtboxEditNodeName_31").getValue();
                    objService.description = this.block.getDescendantOfName("blkEditDescription_31").getChild(0).getValue();
                    objService.machineName = this.block.getDescendantOfName("slctEditMachineName_31").getText();
                    objService.installAsNTService = (this.block.getDescendantOfName("blkEditInstallAsNTService_31").getChild(0).getSelected() == jsx3.gui.RadioButton.SELECTED);
                    objService.messageServer = this.block.getDescendantOfName("slctEditMessageServer_31").getText();
                    objService.namingPort = this.block.getDescendantOfName("txtboxEditNamingPort_31").getValue();
                    objService.httpPort = this.block.getDescendantOfName("txtboxEditHTTPPort_31").getValue();
                    objService.envId = this.envId;
                    objService.nodeId = this.nodeId;
                    var prod = this.getRecordForId(this.block.getDescendantOfName("slctEditProduct_31").getXML(), this.block.getDescendantOfName("slctEditProduct_31").getValue());
                    objService.tibcoHome = prod.getAttribute("tibcoHome");
                    objService.installDir = prod.getAttribute("installDir");
                    objService.major = prod.getAttribute("major");
                    objService.minor = prod.getAttribute("minor");
                    objService.maintenance = prod.getAttribute("maintenance");
                    if(prod.getAttribute("fragment")) {
                        objService.fragment = prod.getAttribute("fragment");
                    }
                    var me = this;
                    objService.subscribe(jsx3.net.Service.ON_SUCCESS, me, me.onaddNodeSuccess);
                    objService.subscribe(jsx3.net.Service.ON_ERROR, me, me.onaddNodeError);
                    objService.subscribe(jsx3.net.Service.ON_INVALID, me, me.onaddNodeInvalid);
                    objService.doCall();
                }
                catch(ex) {
                    tibco.admin.Main.logException(ex, "Error in tibco.admin.environments.genDtls.GenDtls.addNode");
                }
            }

            plugin.prototype.onaddNodeSuccess = function(objEvent) {
                var doc = tibco.admin.Main.getServer().getCache().getDocument("addNode_31");
                if(doc) {
                    this.doViewMode();
                    var val = doc.getAttribute("nodeId");
                    this.addCompleted(val);
                    this.isAddMode = false;
                }
            }

            plugin.prototype.onaddNodeError = function(objEvent) {
            }

            plugin.prototype.onaddNodeInvalid = function(objEvent) {
            }

            plugin.prototype.doEditNode = function() {
                try {
                    var objService = tibco.admin.Main.loadService("tibco.admin", "tibco/admin/environments/genDtls/rules/editNode.xml", "editNode");
                    if(tibco.admin.Main.getServer().getEnv("MODE")) {
                        objService.setEndpointURL(tibco.admin.util.ServiceHelper.getNodeEndpointURL());
                    }

                    //subscribe and call
                    objService.nodeName = this.block.getDescendantOfName("txtboxEditNodeName_31").getValue();
                    objService.description = this.block.getDescendantOfName("blkEditDescription_31").getChild(0).getValue();
                    objService.machineName = this.block.getDescendantOfName("slctEditMachineName_31").getText();
                    objService.installAsNTService = (this.block.getDescendantOfName("blkEditInstallAsNTService_31").getChild(0).getSelected() == jsx3.gui.RadioButton.SELECTED);
                    objService.messageServer = this.block.getDescendantOfName("slctEditMessageServer_31").getText();
                    objService.namingPort = this.block.getDescendantOfName("txtboxEditNamingPort_31").getValue();
                    objService.httpPort = this.block.getDescendantOfName("txtboxEditHTTPPort_31").getValue();
                    objService.envId = this.envId;
                    objService.nodeId = this.nodeId;
                    var prod = this.getRecordForId(this.block.getDescendantOfName("slctEditProduct_31").getXML(), this.block.getDescendantOfName("slctEditProduct_31").getValue());
                    objService.tibcoHome = prod.getAttribute("tibcoHome");
                    objService.installDir = prod.getAttribute("installDir");
                    objService.major = prod.getAttribute("major");
                    objService.minor = prod.getAttribute("minor");
                    objService.maintenance = prod.getAttribute("maintenance");
                    if(prod.getAttribute("fragment")) {
                        objService.fragment = prod.getAttribute("fragment");
                    }
                    var me = this;
                    objService.subscribe(jsx3.net.Service.ON_SUCCESS, me, me.oneditNodeSuccess);
                    objService.subscribe(jsx3.net.Service.ON_ERROR, me, me.oneditNodeError);
                    objService.subscribe(jsx3.net.Service.ON_INVALID, me, me.oneditNodeInvalid);
                    objService.doCall();
                }
                catch(ex) {
                    tibco.admin.Main.logException(ex, "Error in tibco.admin.environments.genDtls.GenDtls.editNode");
                }
            }

            plugin.prototype.oneditNodeSuccess = function(objEvent) {
                this.doViewMode();
                this.addCompleted(null);
            }

            plugin.prototype.oneditNodeError = function(objEvent) {
            }

            plugin.prototype.oneditNodeInvalid = function(objEvent) {
            }

            plugin.prototype.doViewMode = function() {
                this.block.getDescendantOfName("txtboxEditNodeName_31").setValue("").setDisplay(jsx3.gui.Block.DISPLAYNONE, true);
                this.block.getDescendantOfName("blkEditDescription_31").getChild(0).setValue(null);
                this.block.getDescendantOfName("blkEditDescription_31").setDisplay(jsx3.gui.Block.DISPLAYNONE, true);
                this.block.getDescendantOfName("slctEditMachineName_31").setValue(null).setDisplay(jsx3.gui.Block.DISPLAYNONE, true);
                this.block.getDescendantOfName("blkEditInstallAsNTService_31").setDisplay(jsx3.gui.Block.DISPLAYNONE, true).getChild(1).setSelected(jsx3.gui.RadioButton.SELECTED);
                this.block.getDescendantOfName("slctEditProduct_31").setDisplay(jsx3.gui.Block.DISPLAYNONE, true);
                this.block.getDescendantOfName("slctEditMessageServer_31").setDisplay(jsx3.gui.Block.DISPLAYNONE, true).setValue(null, true);
                this.block.getDescendantOfName("txtboxEditNamingPort_31").setValue("").setDisplay(jsx3.gui.Block.DISPLAYNONE, true);
                this.block.getDescendantOfName("txtboxEditHTTPPort_31").setValue("").setDisplay(jsx3.gui.Block.DISPLAYNONE, true);

                this.block.getDescendantOfName("lblViewNodeName_31").setText("").setDisplay(jsx3.gui.Block.DISPLAYBLOCK, true);
                this.block.getDescendantOfName("lblViewDescription_31").setText("").setDisplay(jsx3.gui.Block.DISPLAYBLOCK, true);
                this.block.getDescendantOfName("lblViewMachineName_31").setText("").setDisplay(jsx3.gui.Block.DISPLAYBLOCK, true);
                this.block.getDescendantOfName("lblViewInstallAsNTService_31").setText("").setDisplay(jsx3.gui.Block.DISPLAYBLOCK, true);
                this.block.getDescendantOfName("lblViewProduct_31").setText("").setDisplay(jsx3.gui.Block.DISPLAYBLOCK, true);
                this.block.getDescendantOfName("lblViewMessageServer_31").setText("").setDisplay(jsx3.gui.Block.DISPLAYBLOCK, true);
                this.block.getDescendantOfName("lblViewNamingPort_31").setText("").setDisplay(jsx3.gui.Block.DISPLAYBLOCK, true);
                this.block.getDescendantOfName("lblViewHTTPPort_31").setText("").setDisplay(jsx3.gui.Block.DISPLAYBLOCK, true);

                this.block.getDescendantOfName("btnCancel_31").setDisplay(jsx3.gui.Block.DISPLAYNONE, true);
                this.block.getDescendantOfName("btnSave_31").setDisplay(jsx3.gui.Block.DISPLAYNONE, true);
                this.block.getDescendantOfName("btnEdit_31").setDisplay(jsx3.gui.Block.DISPLAYBLOCK, true);

                this.isAddMode = false;
                if(this.isInEditMode()) {
                    this.endEditMode();
                }

                this.loadProducts();
            }

            plugin.prototype.onUILoaded = function(objEvent) {
                delete this.loading;
                if(objEvent.status == "SUCCESS") {
                    this.block = objEvent.obj;
                    this.block.getDescendantOfName("btnEdit_31").setEnabled((this.nodeState == "Starting") ? jsx3.gui.Form.STATEDISABLED : jsx3.gui.Form.STATEENABLED, true);
                    var me = this;
                    this.block.handler = me;
                    if(this.nodeId) {
                        this.loadDetails();
                    }
                    if(this.isAddMode) {
                        this.newNode();
                    }
                }
                else {
                    if(objEvent.exception)
                    {
                        tibco.admin.Main.logException(objEvent.exception, objEvent.message);
                    }
                    else {
                        jsx3.log(objEvent.message);
                    }
                }
            }

            plugin.prototype.doValidate = function(obj) {
                if(!obj.doValidate()) {
                    obj.setValue("");
                    tibco.admin.Main.alert("Error", tibco.admin.Main.getServer().getDynamicProperty("@@msgNodeNameInvalid_31"));
                }
            }

            plugin.prototype.getComponentPath = function() {
                return "tibco/admin/environments/genDtls/component.xml"
            }

            plugin.prototype.buttonSelected = function() {
                if(!this.isInEditMode() && this.nodeId) {
                    this.loadDetails();
                }
            }

            /*071023
           * if user doesn't fishish all the required fields, the "save" button will be disabled.
           */
            plugin.prototype.passedItems = {};
            plugin.prototype.initializeParam = function() {
                this.passedItems = {};

                // give notified color for validations.
                this.block.getDescendantOfName("txtboxEditNodeName_31")._notifiedColor = "#FFECA0";
                this.block.getDescendantOfName("slctEditMessageServer_31")._notifiedColor = "#FFECA0";
                this.block.getDescendantOfName("txtboxEditNamingPort_31")._notifiedColor = "#FFECA0";
                this.block.getDescendantOfName("slctEditMachineName_31")._notifiedColor = "#FFECA0";
                this.block.getDescendantOfName("slctEditProduct_31")._notifiedColor = "#FFECA0";

                this.passedItems["name"] = tibco.admin.util.Validation.doValidateNotEmpty(this.block.getDescendantOfName("txtboxEditNodeName_31"), null, tibco.admin.Main.getServer().getDynamicProperty("@@lblName_31"))
                this.passedItems["msgServer"] = tibco.admin.util.Validation.doValidateSelectBox(this.block.getDescendantOfName("slctEditMessageServer_31"), tibco.admin.Main.getServer().getDynamicProperty("@@lblMessagingServer_31"));
                this.passedItems["port"] = tibco.admin.util.Validation.doValidateNotEmpty(this.block.getDescendantOfName("txtboxEditNamingPort_31"), null, tibco.admin.Main.getServer().getDynamicProperty("@@lblNamingPort_31"));
                this.passedItems["machine"] = tibco.admin.util.Validation.doValidateSelectBox(this.block.getDescendantOfName("slctEditMachineName_31"), tibco.admin.Main.getServer().getDynamicProperty("@@lblMachineName_31"));
                this.passedItems["product"] = tibco.admin.util.Validation.doValidateSelectBox(this.block.getDescendantOfName("slctEditProduct_31"), tibco.admin.Main.getServer().getDynamicProperty("@@lblProduct_31"));
                this.enableSaveBtn4Add();
            }

            plugin.prototype.valiName = function(obj, strValue) {
                this.passedItems["name"] = tibco.admin.util.Validation.doValidateNotEmpty(obj, strValue, tibco.admin.Main.getServer().getDynamicProperty("@@lblName_31"));
                this.enableSaveBtn4Add();
            }

            plugin.prototype.valiMsgServer = function(obj) {
                this.passedItems["msgServer"] = tibco.admin.util.Validation.doValidateSelectBox(obj, tibco.admin.Main.getServer().getDynamicProperty("@@lblMessagingServer_31"));
                this.enableSaveBtn4Add();
            }

            plugin.prototype.valiPort = function(obj, strValue) {
                this.passedItems["port"] = tibco.admin.util.Validation.doValidatePort(obj, strValue);
                this.enableSaveBtn4Add();
            }

            plugin.prototype.valiMachine = function(obj) {
                this.passedItems["machine"] = tibco.admin.util.Validation.doValidateSelectBox(obj, tibco.admin.Main.getServer().getDynamicProperty("@@lblMachineName_31"));
                this.enableSaveBtn4Add();
            }

            plugin.prototype.valiProduct = function(obj) {
                this.passedItems["product"] = tibco.admin.util.Validation.doValidateSelectBox(obj, tibco.admin.Main.getServer().getDynamicProperty("@@lblProduct_31"));
                this.enableSaveBtn4Add();
            }

            plugin.prototype.enableSaveBtn4Add = function() {
                var allPassed = true;
                for (var item in this.passedItems) {
                    if (!this.passedItems[item]) allPassed = false;
                }
                if (allPassed) this.block.getDescendantOfName("btnSave_31").setEnabled(jsx3.gui.Form.STATEENABLED, true);
                else this.block.getDescendantOfName("btnSave_31").setEnabled(jsx3.gui.Form.STATEDISABLED, true);
            }
        });